<%--
  Created by IntelliJ IDEA.
  User: xianfei
  Date: 15-5-29
  Time: 下午2:49
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %>
<%@ taglib prefix="s" uri="http://www.springframework.org/tags" %>
<html lang="zh">
<head>
    <title>测试</title>
    <script type="text/javascript">
        $(function () {
            $("#btn").click(function () {
                var a = $("#input").val();
                var reg = /([a-zA-Z]+=[0-9]{1})+$/;
                if (reg.test(a)) {
                    console.log("true");
                } else {
                    console.log("false");
                }
            })

            $.ajax({
                url: "/",
                type: 'post',
                dataType: 'json',
                contentType: 'application/json;charset=utf-8',
                data: JSON.stringify({name: 'xiaoming', age: 12}),
            })

        })

        function doExchange(arr) {  //二维数组排列组合
            var len = arr.length;
            // 当数组大于等于2个的时候
            if (len >= 2) {
                // 第一个数组的长度
                var len1 = arr[0].length;
                // 第二个数组的长度
                var len2 = arr[1].length;
                // 2个数组产生的组合数
                var lenBoth = len1 * len2;
                //  申明一个新数组
                var items = new Array(lenBoth);
                // 申明新数组的索引
                var index = 0;
                for (var i = 0; i < len1; i++) {
                    for (var j = 0; j < len2; j++) {
                        if (arr[0][i] instanceof Array) {
                            items[index] = arr[0][i].concat(arr[1][j]);
                        } else {
                            items[index] = [arr[0][i]].concat(arr[1][j]);
                        }
                        index++;
                    }
                }
                var newArr = new Array(len - 1);
                for (var i = 2; i < arr.length; i++) {
                    newArr[i - 1] = arr[i];
                }
                newArr[0] = items;
                return doExchange(newArr);
            } else {
                return arr[0];
            }
        }

        function test() {
            var arr = [['语文A', '语文B', '语文C'], ['数学A', '数学B'], ['英语A', '英语B', '英语C', '英语D']];
            console.log(doExchange(arr));
        }

        //获取字符串长度（汉字算两个字符，字母数字算一个）
        function getByteLen(val) {
            var len = 0;
            for (var i = 0; i < val.length; i++) {
                var a = val.charAt(i);
                if (a.match(/[^\x00-\xff]/ig) != null) {
                    len += 2;
                }
                else {
                    len += 1;
                }
            }
            return len;
        }

        function checkLength(obj) {
            var maxChars = 300;//最多字符数
            var curr = maxChars - getByteLen(obj.value);
            if (curr > 0) {
                document.getElementById("checklen").innerHTML = curr.toString();
            } else {
                document.getElementById("checklen").innerHTML = '0';
                obj.value = obj.value.substring(0, maxChars);
            }
        }
    </script>
</head>
<body>
<form action="/public/resize_upload" method="post" enctype="multipart/form-data">
    <input type="file" name="file">
    <input type="submit" value="submit">
</form>
<hr/>
<s:message code="lxf.zh"/>
<s:url value="/lxf/{age}" var="lxfurl" javaScriptEscape="true">
    <s:param name="age" value="22"/>
</s:url>
<a href="${lxfurl}">点我呀</a>
<%--<form:form commandName="goodDTO">--%>
<%--<form:checkboxes path="strs" items="${goodDTO.map}"></form:checkboxes>--%>
<%--</form:form>--%>
<div>
    <textarea onkeyup="checkLength(this)"></textarea>
    <span>还可以输入<span id="checklen"></span>个字符</span>
</div>
<myScript>
    <script>
        var url = "${lxfurl}";
    </script>
</myScript>
</body>
</html>